Imports System.Data.OleDb
Imports System.IO
Imports system.Text
Imports System.Xml

Public Class VersionUpdater

    Private Const VersionSQL As String = "SELECT version FROM Settings"

    Public Const CurrentVersion As Single = 2.0
    Private Const DefaultVersion As Single = 1.0

    Private Const UpgradeSucceededMessage As String = "Upgrade Succeeded."
    Private Const UpgradeFailedMessage As String = "Upgrade failed."

    Private Const VersionFileName As String = "version.xml"
    Private Const VersionErrorMessage As String = "Failure when determining latest version"


#Region " Upgrade SQL "

    Private Const VersionCreateSQL As String = "CREATE TABLE Settings (Version Single NOT NULL)"
    Private Const AddVersionSQL As String = "INSERT INTO Settings (Version) VALUES (1.0)"
    Private Const UpdateVersionSQL As String = "UPDATE Settings SET Version = {0}"
    Private Const InstalledRuntimesCreateSQL As String = "CREATE TABLE InstalledRuntimes (installed_id Counter(1,1) PRIMARY KEY, file_id INTEGER NOT NULL REFERENCES Files(file_id), runtime TEXT NOT NULL)"
    Private Const FiguresCreateSQL As String = "CREATE TABLE Figures (name TEXT(255) NOT NULL PRIMARY KEY)"
    Private Const AddFigureSQL As String = "INSERT INTO Figures (name) VALUES ('{0}')"
    Private Const FileForFigureCreateSQL As String = "CREATE TABLE FileForFigure (ff_id COUNTER(1,1) PRIMARY KEY, file_id INTEGER NOT NULL REFERENCES Files(file_id), figure TEXT(255) NOT NULL)"
    Private Const RequiredProductCreateSQL As String = "CREATE TABLE RequiredProduct (rp_id COUNTER(1,1) PRIMARY KEY, file_id INTEGER NOT NULL REFERENCES Files(file_id), required_product TEXT(255) NOT NULL)"
    Private Const ProductTypeCreateSQL As String = "CREATE TABLE ProductType (type_name TEXT(255) NOT NULL PRIMARY KEY)"
    Private Const AddProductTypeSQL As String = "INSERT INTO ProductType (type_name) VALUES ('{0}')"
    Private Const FileProductTypeCreateSQL As String = "CREATE TABLE FileProductType (fpt_id COUNTER(1,1) PRIMARY KEY, file_id INTEGER NOT NULL REFERENCES Files(file_id), product_type TEXT(255) NOT NULL)"
    Private Const FileImageCreateSQL As String = "CREATE TABLE FileImage (fi_id COUNTER(1,1) PRIMARY KEY, file_id INTEGER NOT NULL REFERENCES Files(file_id), image_name TEXT(255) NOT NULL)"
    Private Const FileArtistCreateSQL As String = "CREATE TABLE FileArtist (fa_id COUNTER(1,1) PRIMARY KEY, file_id INTEGER NOT NULL REFERENCES Files(file_id), artist TEXT(255) NOT NULL)"
    Private Const VendorCreateSQL As String = "CREATE TABLE Vendor (vendor_name TEXT(255) NOT NULL PRIMARY KEY)"


    Private Const AddCommentsColumnSQL As String = "ALTER TABLE Files ADD COLUMN Comments MEMO"
    Private Const AddDSOnlyColumnSQL As String = "ALTER TABLE Files ADD COLUMN DSOnly BIT"
    Private Const AddMinPoserVersionColumnSQL As String = "ALTER TABLE Files ADD COLUMN MinPoserVersion TEXT(2)"

    Private Const AddInstalledColumnSQL As String = "ALTER TABLE Files ADD COLUMN Installed BIT"
    Private Const AddLocalImageColumnSQL As String = "ALTER TABLE Files ADD COLUMN LocalImage BIT"
    Private Const AddImageNameColumnSQL As String = "ALTER TABLE Files ADD COLUMN ImageName TEXT(255)"

    Private Const AddRequirementsColumnSQL As String = "ALTER TABLE Files ADD COLUMN Requirements MEMO)"

    Private Const AddPricePaidColumnSQL As String = "ALTER TABLE Files ADD COLUMN price_paid CURRENCY"
    Private Const AddFileSizeColumnSQL As String = "ALTER TABLE Files ADD file_size INTEGER"
    Private Const AddDownloadDateColumnsSQL As String = "ALTER TABLE Files ADD date_of_download DATE"
    Private Const AddOrderNumberColumnsSQL As String = "ALTER TABLE Files ADD order_number TEXT(255)"
    Private Const AddImportedIdColumnSQL As String = "ALTER TABLE Files ADD imported_id INTEGER"
    Private Const AddImportedFromColumnSQL As String = "ALTER TABLE Files ADD imported_from TEXT(5)"
    Private Const AddFileFigurerUniqueConstraintSQL As String = "ALTER TABLE FileForFigure ADD CONSTRAINT UFileFigure UNIQUE (file_id, figure)"

    Private Const AddFileArtistUniqueConstraintSQL As String = "ALTER TABLE FileArtist ADD CONSTRAINT UFileArtist UNIQUE (file_id, artist)"
    Private Const AddFileImportedIndexSQL As String = "CREATE INDEX IFileImported ON Files (imported_id, imported_from)"

    Private Const AddConnectionStatusColumnSQL As String = "ALTER TABLE Settings ADD COLUMN Online BIT"
    Private Const UpdateConnectionStatusSQL As String = "UPDATE Settings SET Online = 1"

    Private Const AddUserAddedColumnSQL As String = "ALTER TABLE Provider ADD COLUMN UserAdded BIT"
    Private Const AddReadMeColumnSQL As String = "ALTER TABLE Files ADD COLUMN ReadMe MEMO"
    Private Const LicenseCreateSQL As String = "CREATE TABLE License (l_id COUNTER(1,1) PRIMARY KEY, license_type TEXT(255) NOT NULL UNIQUE, license_text MEMO)"
    Private Const AddLicenseColumnSQL As String = "ALTER TABLE Files ADD COLUMN license TEXT(255) NULL"

    Private Const AlterLicenseColumnSQL As String = "ALTER TABLE Files ALTER COLUMN license INTEGER NULL"
    Private Const AddLicenseIndexSQL As String = "CREATE INDEX IFileLicense ON Files (license)"
    Private Const AddFileArtistArtistIndexSQL As String = "CREATE INDEX IFileArtistArtist ON FileArtist (artist)"

    Private Const AddFileVendorIndexSQL As String = "CREATE INDEX IFileVendor ON Files (vendor)"

    'Private Const AddFileArtistCascadeDeletesSQL As String = "ALTER TABLE FileArtist ALTER COLUMN file_id INTEGER NOT NULL REFERENCES Files(file_id) ON DELETE CASCADE"

    Private Const AddActualLocationColumnSQL As String = "ALTER TABLE Files ADD actual_location MEMO"

    Private Const AddProviderSQL As String = "INSERT INTO Provider (provider_name) VALUES ('{0}')"


#End Region

#Region " Expected Error Messages "

    Private Const ExpectedColumnExistsErrorCode As Integer = -2147217887
    Private Const ExpectedIndexExistsErrorCode As Integer = -2147467259
    Private Const ExpectedTableExistsErrorCode As Integer = -2147217900
    Private Const ExpectedPrimaryKeyViolationErrorCode As Integer = -2147467259

    'Private Const CommentColumnExists As String = "Field 'Comments' already exists in table 'Files'."
    'Private Const DSOnlyColumnExists As String = "Field 'DSOnly' already exists in table 'Files'."
    'Private Const MinPoserVersionColumnExists As String = "Field 'MinPoserVersion' already exists in table 'Files'."
    'Private Const InstalledColumnExists As String = "Field 'Installed' already exists in table 'Files'."
    'Private Const LocalImageColumnExists As String = "Field 'LocalImage' already exists in table 'Files'."
    'Private Const ImageNameColumnExists As String = "Field 'ImageName' already exists in table 'Files'."
    'Private Const ConnectionStatusColumnExists As String = "Field 'Online' already exists in table 'Settings'."
    'Private Const RequirementsColumnExists As String = "Field 'Requirements' already exists in table 'Files'."
    'Private Const PricePaidColumnExists As String = "Field 'price_paid' already exists in table 'Files'."
    'Private Const FileSizeColumnExists As String = "Field 'file_size' already exists in table 'Files'."
    'Private Const DateOfDownloadColumnExists As String = "Field 'date_of_download' already exists in table 'Files'."
    'Private Const OrderNumberColumnExists As String = "Field 'order_number' already exists in table 'Files'."
    'Private Const ImportedIdColumnExists As String = "Field 'imported_id' already exists in table 'Files'."
    'Private Const ImportedFromColumnExists As String = "Field 'imported_from' already exists in table 'Files'."
    'Private Const UserAddedColumnExists As String = "Field 'UserAdded' already exists in table 'Provider'."
    'Private Const ReadMeColumnExists As String = "Field 'ReadMe' already exists in table 'Files'."
    'Private Const LicenseColumnExists As String = "Field 'license' already exists in table 'Files'."
    'Private Const ActualLocationColumnExists As String = "Field 'actual_location' already exists in table 'Files'."

    'Private Const SettingsExists As String = "Table 'Settings' already exists."
    'Private Const InstalledRuntimesExists As String = "Table 'InstalledRuntimes' already exists."
    'Private Const FiguresExists As String = "Table 'Figures' already exists."
    'Private Const FileForFigureExists As String = "Table 'FileForFigure' already exists."
    'Private Const RequiredProductExists As String = "Table 'RequiredProduct' already exists."
    'Private Const ProductTypeExists As String = "Table 'ProductType' already exists."
    'Private Const FileProductTypeExists As String = "Table 'FileProductType' already exists."
    'Private Const FileImageExists As String = "Table 'FileImage' already exists."
    'Private Const FileArtistExists As String = "Table 'FileArtist' already exists."
    'Private Const LicenseExists As String = "Table 'License' already exists."
    'Private Const VendorExists As String = "Table 'Vendor' already exists."

    'Private Const FileFigureConstraintExists As String = "Table 'FileForFigure' already has an index named 'UFileFigure'."
    'Private Const FileArtistConstraintExists As String = "Table 'FileArtist' already has an index named 'UFileArtist'."


    'Private Const FileImportedIndexExists As String = "Table 'Files' already has an index named 'IFileImported'."
    'Private Const FileLicenseIndexExists As String = "Table 'Files' already has an index named 'IFileLicense'."
    'Private Const FileArtistsArtistIndexExists As String = "Table 'FileArtist' already has an index named 'IFileArtistArtist'."
    'Private Const FileVendorIndexExists As String = "Table 'Files' already has an index named 'IFileVendor'."

    'Private Const PrimaryKeyViolation As String = "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship.  Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."


#End Region

    Private Sub New()

    End Sub

#Region " Version 1.1 Upgrades "

    Private Shared Sub AddCommentsColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddCommentsColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddCommentsColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddCommentsColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddCommentsColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddDSOnlyColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddDSOnlyColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddDSOnlyColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddDSOnlyColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddDSOnlyColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddMinPoserVersionColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddMinPoserVersionColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddMinPoserVersionColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddMinPoserVersionColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddMinPoserVersionColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateInstalledRuntimesTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = InstalledRuntimesCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("CreateInstalledRuntimesTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateInstalledRuntimesTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateInstalledRuntimesTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateSettingsTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = VersionCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            comm = New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddVersionSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("CreateSettingsTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateSettingsTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateSettingsTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region


#Region " Version 1.2 Upgrades "

    Private Shared Sub AddInstalledColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddInstalledColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddInstalledColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddInstalledColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddInstalledColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddLocalImageColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddLocalImageColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddLocalImageColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddLocalImageColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddLocalImageColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddImageNameColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddImageNameColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddImageNameColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddImageNameColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddImageNameColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddConnectionStatusColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddConnectionStatusColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            Try
                comm = New OleDbCommand
                comm.CommandType = CommandType.Text
                comm.CommandText = UpdateConnectionStatusSQL
                comm.Connection = conn

                comm.ExecuteNonQuery()
            Catch ex As Exception
                'none fatal error and doesn't mean a failed upgrade so ignore
            End Try

            UpgradeLog.WriteEntry("AddConnectionStatusColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddConnectionStatusColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddConnectionStatusColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateFiguresTable()

        Dim conn As New OleDbConnection
        Dim figuresToAdd() As String = {"V1", "V2", "V3", "V4", "Stephanie", "SP3", "Aiko", "A3", "M1", "M2", "M3", "David", "H3", "Alexa", "Alexa2", "Laroo", "Laroo2", "AM2005", "AM2006", "AM2007", "AD", "MD", "F202"}
        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = FiguresCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            For Each figure As String In figuresToAdd

                comm = New OleDbCommand
                comm.CommandType = CommandType.Text
                comm.CommandText = String.Format(AddFigureSQL, figure)
                comm.Connection = conn

                comm.ExecuteNonQuery()

            Next

            UpgradeLog.WriteEntry("CreateFiguresTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateFiguresTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateFiguresTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateFileForFigureTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = FileForFigureCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()


            UpgradeLog.WriteEntry("CreateFileForFigureTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateFileForFigureTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateFileForFigureTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region

#Region " Version 1.3 Upgrades "

    Private Shared Sub AddNewFigures()

        Dim conn As New OleDbConnection
        Dim figuresToAdd() As String = {"Koshini", "Koshini2", "Ichiro", "Ichiro2", "Krystal", "Kiki", "Patches", "Leroy", "Sakari", "Lorelei", "Jingles", "Dexter", "Chloe", "Sara", "Girl", "Kit", "Miki 1020", "Miki 2", "TY2", "Jessi", "Jessi G2", "James", "MilBaby", "MilGirls", "MilBoys", "Luke", "Laura", "Staci", "MilKids - Preschool", "Freak", "She-Freak", "P4 Male", "P4 Female", "Koji", "Sydney", "Simon", "Judy"}
        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As OleDbCommand

            For Each figure As String In figuresToAdd

                comm = New OleDbCommand
                comm.CommandType = CommandType.Text
                comm.CommandText = String.Format(AddFigureSQL, figure)
                comm.Connection = conn

                Try
                    comm.ExecuteNonQuery()
                Catch ex As OleDbException
                    If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                        Throw
                    End If
                End Try
            Next

            UpgradeLog.WriteEntry("AddNewFigures Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("AddNewFigures failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddNewFigures failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateRequiredProductTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = RequiredProductCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()


            UpgradeLog.WriteEntry("CreateRequiredProductTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateRequiredProductTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateRequiredProductTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateProductTypeTable()

        Dim conn As New OleDbConnection
        Dim productTypesToAdd() As String = {"Figure", "Hair - Mesh", "Hair - Texture", "Clothing - Mesh", "Clothing - Texture", "Character - Morph", "Character - Texture", "Pose", "Morph Targets", "Architecture", "Creatures/Animals", "Lights", "Scenes/Sets", "Weapons", "Vehicles", "Headgear/Jewelry"}
        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = ProductTypeCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            For Each productType As String In productTypesToAdd

                comm = New OleDbCommand
                comm.CommandType = CommandType.Text
                comm.CommandText = String.Format(AddProductTypeSQL, productType)
                comm.Connection = conn

                comm.ExecuteNonQuery()

            Next

            UpgradeLog.WriteEntry("CreateProductTypeTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateProductTypeTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateProductTypeTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateFileProductTypeTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = FileProductTypeCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()


            UpgradeLog.WriteEntry("CreateFileProductTypeTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateFileProductTypeTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateFileProductTypeTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddRequirementsColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddRequirementsColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddRequirementsColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddRequirementsColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddRequirementsColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region

#Region " Version 1.4 Upgrades "

    Private Shared Sub AddNewFigures2()

        Dim conn As New OleDbConnection
        Dim figuresToAdd() As String = {"V2RR", "V3RR", "M2RR", "M3RR"}
        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As OleDbCommand

            For Each figure As String In figuresToAdd

                comm = New OleDbCommand
                comm.CommandType = CommandType.Text
                comm.CommandText = String.Format(AddFigureSQL, figure)
                comm.Connection = conn

                Try
                    comm.ExecuteNonQuery()
                Catch ex As OleDbException
                    If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                        Throw
                    End If
                End Try
            Next

            UpgradeLog.WriteEntry("AddNewFigures2 Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("AddNewFigures2 failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddNewFigures2 failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddPricePaidColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddPricePaidColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddPricePaidColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddPricePaidColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddPricePaidColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddFileSizeColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddFileSizeColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddFileSizeColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddFileSizeColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddFileSizeColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddDateOfDownloadColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddDownloadDateColumnsSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddDateOfDownloadColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddDateOfDownloadColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddDateOfDownloadColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateFileImageTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = FileImageCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()


            UpgradeLog.WriteEntry("CreateFileImageTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateFileImageTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateFileImageTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateFileArtistTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = FileArtistCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()


            UpgradeLog.WriteEntry("CreateFileArtistTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateFileArtistTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateFileArtistTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddFileFigureConstraint()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddFileFigurerUniqueConstraintSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddFileFigureConstraint Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                UpgradeLog.WriteEntry("AddFileFigureConstraint failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddFileFigureConstraint failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddOrderNumberColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddOrderNumberColumnsSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddOrderNumberColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddOrderNumberColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddOrderNumberColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddImportedIdColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddImportedIdColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddImportedIdColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddImportedIdColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddImportedIdColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddImportedFromColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddImportedFromColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddImportedFromColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddImportedFromColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddImportedFromColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region

#Region " Version 1.5 Upgrades "

    Private Shared Sub AddFileArtistConstraint()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddFileArtistUniqueConstraintSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddFileArtistConstraint Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                UpgradeLog.WriteEntry("AddFileArtistConstraint failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddFileArtistConstraint failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddFileImportedIndex()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddFileImportedIndexSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddFileImportedIndex Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedIndexExistsErrorCode Then
                UpgradeLog.WriteEntry("AddFileImportedIndex failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddFileImportedIndex failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region

#Region " Version 1.6 Upgrades "

    Private Shared Sub AddNewProviders()

        Dim conn As New OleDbConnection
        Dim providersToAdd() As String = {"Teknology 3D", "e-frontier", "3D Universe"}
        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As OleDbCommand

            For Each provider As String In providersToAdd

                comm = New OleDbCommand
                comm.CommandType = CommandType.Text
                comm.CommandText = String.Format(AddProviderSQL, provider)
                comm.Connection = conn

                Try
                    comm.ExecuteNonQuery()
                Catch ex As OleDbException
                    If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                        Throw
                    End If
                End Try
            Next

            UpgradeLog.WriteEntry("AddNewProviders Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("AddNewProviders failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddNewProviders failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddUserAddedColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddUserAddedColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddUserAddedColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddUserAddedColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddUserAddedColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddReadMeColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddReadMeColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddReadMeColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddReadMeColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddReadMeColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateLicenseTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = LicenseCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("CreateLicenseTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateLicenseTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateLicenseTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddLicenseColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddLicenseColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddLicenseColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddLicenseColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddLicenseColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region


#Region " Version 1.7 Upgrades "

    Private Shared Sub AlterLicenseColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AlterLicenseColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AlterLicenseColumn Succeeded.")

        Catch ex As OleDbException
            'If ex.Message <> LicenseColumnExists Then
            UpgradeLog.WriteEntry("AlterLicenseColumn failed: " & ex.Message)
            Throw
            'End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AlterLicenseColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddLicenseIndex()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddLicenseIndexSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddLicenseIndex Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedIndexExistsErrorCode Then
                UpgradeLog.WriteEntry("AddLicenseIndex failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddLicenseIndex failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddFileArtistArtistIndex()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddFileArtistArtistIndexSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddFileArtistArtistIndex Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedIndexExistsErrorCode Then
                UpgradeLog.WriteEntry("AddFileArtistArtistIndex failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddFileArtistArtistIndex failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region


#Region " Version 1.8 Upgrades "

    Private Shared Sub AddVendorIndex()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddFileVendorIndexSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddVendorIndex Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedIndexExistsErrorCode Then
                UpgradeLog.WriteEntry("AddVendorIndex failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddVendorIndex failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

#End Region


#Region " Version 1.10 Upgrades "

    Private Shared Sub AddActualLocationColumn()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = AddActualLocationColumnSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("AddActualLocationColumn Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedColumnExistsErrorCode Then
                UpgradeLog.WriteEntry("AddActualLocationColumn failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddActualLocationColumn failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub



    Private Shared Sub AddNewFigures3()

        Dim conn As New OleDbConnection
        Dim figuresToAdd() As String = {"MilKids - Young Teens", _
                                        "MilDog", _
                                        "House Mouse", _
                                        "Nybras", _
                                        "MilDragon 2", _
                                        "MilHorse", _
                                        "MilCat", _
                                        "Bryce", _
                                        "DazStudio"}
        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As OleDbCommand

            For Each figure As String In figuresToAdd

                comm = New OleDbCommand
                comm.CommandType = CommandType.Text
                comm.CommandText = String.Format(AddFigureSQL, figure)
                comm.Connection = conn

                Try
                    comm.ExecuteNonQuery()
                Catch ex As OleDbException
                    If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                        Throw
                    End If
                End Try
            Next

            UpgradeLog.WriteEntry("AddNewFigures3 Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("AddNewFigures3 failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddNewFigures3 failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub CreateVendorTable()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = VendorCreateSQL
            comm.Connection = conn

            comm.ExecuteNonQuery()


            UpgradeLog.WriteEntry("CreateVendorTable Succeeded.")

        Catch ex As OleDbException
            If ex.ErrorCode <> ExpectedTableExistsErrorCode Then
                UpgradeLog.WriteEntry("CreateVendorTable failed: " & ex.Message)
                Throw
            End If
        Catch ex As Exception
            UpgradeLog.WriteEntry("CreateVendorTable failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Sub AddRenderosityVendors()

        Dim vendors As String() = {"-dp-", ".Artemis.", ".mada", ".yvonne.", "1010", "12rounds", _
                                    "2Mylent", "3-DArena", "303dreams", "3D Strike", "3d-Cluster.com", "3dCAT", _
                                    "3dCritter", "3DFever", "3dlands", "3dpmr", "3Dream", "3DRebel", _
                                    "3DRumble", "3DSublimeProductions", "3dtrue", "3DTubeMagic", "3DTurtle", "4blueyes", _
                                    "4colorgrafix", "4udreamcatcher", "7of9", "7SeAs", "A-one", "aaa3d", _
                                    "Aaronheart", "aazaricantharess", "AbaloneLLC", "Abraham", "accidental_alchemy", "ACW", _
                                    "Adamant_2001", "adamthwaites", "AdamWright", "addy", "adh3d", "Adiene", _
                                    "adp001", "Adrian_King", "adrox", "Aery_Soul", "aevi", "Afrodite-Ohki", _
                                    "AGentleMuse", "agxcix", "AG_Studio", "AilsaDS", "Aioria", "Airaelda", _
                                    "Ajax", "akahastur", "Akia", "Alaina", "alegrocher", "Alfons", _
                                    "ali", "alicelefay", "ALIEN51", "aliensprog", "aliwonder", "Alla", _
                                    "almdesign", "alphauser51", "Amaranth", "ambientLight", "AmyD", "amzayle", _
                                    "Anakele", "Anatoliy", "Andi3d", "andygraph", "anewman", "Angel Michael", _
                                    "Angela3D", "angelbearzs", "angele", "Angelic-Fairy", "angelluciano", "Angelmoon", _
                                    "angielyn", "anicode", "animdude", "Anniebel", "anny", "AnotherHell", _
                                    "antje", "antontiefenthaler", "anykl", "aoaio", "AofD", "Aphoennix", _
                                    "AprilYSH", "Arasii", "arcebus", "Archode", "Arduino", "aremar", _
                                    "argus456", "ariaans", "Ariah", "Arien", "Arki", "artangel", _
                                    "artgrafx", "artilens", "artistheat", "artofsw", "Arvanor", "arwenone", _
                                    "AS3Design", "AscendedSpirit", "ashokscape", "asp1vip", "AtelierAriel", "AtharianMedia", _
                                    "Athena59", "ATLANTIS", "AtlantiStyle", "Attic-Wear", "Atze0571", "Aurora_in_a_bag", _
                                    "avalon-graphix", "awax", "awycoff", "axe3677", "Axeye", "Ayreon", _
                                    "ayukawataur", "Ayu_Dream", "azl", "A_", "Banbha", "baramdo", _
                                    "barbie4364", "BarbieDahl", "BarefootArtists", "Baron_Vlad_Harkonnen", "BATLAB", "bazze", _
                                    "Becco_UK", "Benettor", "Benten", "BeoshingusStudios", "bernieloehn", "BeyondVR", _
                                    "Bez", "Bice", "BigRedKane", "Bigt", "BillMTracer", "billy-home", _
                                    "billy-t", "BinkiKitty", "BitterAspartame", "BizzeePosin", "Black Rain", "black-eye", _
                                    "BlackCatStudios", "Blackhearted", "blackwiddow", "Black_Fingernails", "Black_Star", "blankpixel", _
                                    "blaufeld", "Blazerwiccan", "blessed_isis", "bloodsong", "BlueBeard", "BluEcho", _
                                    "BluePenguin", "BluesPadawan", "bluevenus", "blyonn", "bnetta", "Bobbie25", _
                                    "BonBonish", "Borus", "Botticelli", "Botz", "bouncypig", "boundless", _
                                    "BountifulKnight", "bovi", "bradvs", "BrianR", "Briggie", "broken-wings", _
                                    "BrokenWings", "bruelmcbeal", "brycetech", "btsculptor", "bubly", "Bugzlife", _
                                    "Bully_GNs", "bungle", "butterfly_fish", "byheart", "ByteDreams", "c-design", _
                                    "c567591", "caioamaro", "calico1", "Calislahn", "calzgal", "Cama", _
                                    "canary3d", "CandeeKis", "CANTROS", "capsces", "captainsquarters", "caravaggio", _
                                    "carlos-teran", "CarolineG", "cartesius", "cascarda", "catalina", "cate_kroft", _
                                    "Cazcie", "CBro", "ccmt", "Ceassa", "cebarre", "CeeBeeVFXG", _
                                    "Ceki", "Ceridwen", "CGCLUB-MUU", "Ch3rokee", "chall-art", "chaobell", _
                                    "chasmata", "chevybabe25", "chikako", "chris1972", "chriscox", "chrisjol", _
                                    "chrislenn", "Christiandarkin", "ChristineG", "chromecafe", "ChromeStar", "Cimerone", _
                                    "Cin-", "CJ-studio", "ckeri", "Clarissa", "Claywoman", "Clemme", _
                                    "cleopatra1412", "cloughie", "cmdctrlesc", "cocco", "CodemanStudios", "coflek-gnorg", _
                                    "coleus", "colynn", "communion", "compiler", "confusius", "Corinne", _
                                    "cornelp", "corvas", "cplymill", "crampfenburg", "CrimsonRoseDesigns", "Cris_Palomino", _
                                    "CryptoPooka", "CrystalWizard", "Curio", "cwolfe1971", "cwshorty", "CyberGooch", _
                                    "cybia", "Cyncro007", "Cyphre", "c_stone_bush", "d4500", "Da3dalus", _
                                    "dadamson", "daeve", "Daio", "dalinise", "Damsel", "DanaanD", _
                                    "danae", "Danie", "dantescanto", "Dark-Visions-design", "DarkAngelGrafics", "darken666", _
                                    "DarkePhazeGraphiX", "DarkLocke", "darkness_02", "DarkReflections", "DarkSkills", "DarkStarBurning", _
                                    "Darkworld", "Dark_Anvil", "Dave", "Dave Wight", "Dave71", "Daventaki", _
                                    "davinm", "dawnsthemes", "dayglo", "dburdick", "dcort", "deadhead", _
                                    "DefKisum", "Deimos", "DEL", "DeLaCoon", "Delgine", "delluserxp", _
                                    "demonfirefly", "Desideria", "Design-3D", "designfera", "Deskar", "deviney", _
                                    "DexPac", "dfsmetsfan", "Diandra", "didi_mc", "dido6", "DigiCalimero", _
                                    "digilou", "Digital&sparky", "Digital-Lion", "Digital3DStudio", "digitalemotions", "DigitalMercantile", _
                                    "DigitalMetal", "dikaios", "Dimension3D", "Dinoraul", "Discoseven", "dissect", _
                                    "diviner", "DiYanira", "Dizzi", "Django", "DJBlueprint", "dke", _
                                    "DLA", "dladymystic", "dlblue", "dmblnd", "doarte", "doctorjo", _
                                    "doc_jones", "dodixy", "DokieMaster", "dolfijntjes", "dolphing", "Don", _
                                    "Doorman", "dorin", "dorkati", "Dotthy", "Double-T", "dpanzee", _
                                    "Dragill", "DRAKELOT", "dreamlight", "dreampaint", "DreamTeam", "DreamTheatre", _
                                    "DreamWarrior", "Drezz", "drgonzo", "drkmo", "DTigerWoman", "duo", _
                                    "dutchcreator", "dx30", "D_Maersk", "edain", "edhoover", "eeZee", _
                                    "Eismaus", "Eleria", "elisabethc", "Elke", "EllPro", "ElorOnceDark", _
                                    "Elsina", "emilyzz", "EmKay", "Eniy", "Eowyn", "EPhi", _
                                    "Erasor", "ericfarris", "ericwestray", "Erik0815Erik", "erka", "erlaci", _
                                    "esha", "Esterix", "etomchek", "Evanara", "Everseer", "evg3dren", _
                                    "EvilInnocence", "EwanG", "ExistentialDisorder", "expert", "ExprssnImg", "ExtremeThemes", _
                                    "EyesblueDesign", "face_off", "FaerieGuild", "FanDancer", "FantastArt", "Fatale", _
                                    "fatman117", "faveral", "Fazeon", "fcoffill", "fearsome", "Feliciti", _
                                    "fiction2002", "Fillingim", "Firebirdz", "FireMonkey", "FiveEyedFish", "five_by_five", _
                                    "flexi", "flinch67", "Flink", "flying_octopus", "fmorgan", "fmtoffolo", _
                                    "Folded", "FoliFoli", "folkvangar", "forester", "formoz", "fracturedmoon", _
                                    "Franceena", "fran_joel", "Fredy", "FreeeSpirits", "Freja", "FreyrStrongart", _
                                    "Fru.Valentin", "FXRsoft", "Fyrene", "g4dual", "gabriel_mb1", "gcts", _
                                    "GenePoolDesign", "Geodesic250", "geoegress", "geometrya", "GeorgeD", "gepard99", _
                                    "Ghost", "Giana", "gigahedron", "giko", "gillbrooks", "gimley7", _
                                    "giorgiouti", "giuoco", "glassman", "Glayed", "GoblinWorks", "goldtassel", _
                                    "goop", "Gordana", "Gorodin", "gorrel", "gothweaver", "gr8g8s", _
                                    "graphites", "GraphixDesign", "graphixdezine", "greenworks", "greetinx", "Gregc", _
                                    "Greybro", "greyson5", "grid", "griffoso", "Grimpopo", "grom", _
                                    "grotto", "gryffnn", "gtgauvin", "gtrias", "guarie", "guigui", _
                                    "Guillermo", "gwhicks", "gypsyangel", "haegerst", "hahtor", "halcyone", _
                                    "HandspanStudios", "hankim", "hannah", "HansAnders", "HardStuff", "Harrgunn", _
                                    "harry-cn", "Hawke", "Hawkin-Z GraF-X", "Hedda", "Helen", "Hexymaus", _
                                    "heyDerick", "HHDrache", "Hibob", "Hikari_", "hilltech", "HindSightStudios", _
                                    "hipchick", "hitman47", "hmann", "Hobbes", "HocusPocus", "hogwarden", _
                                    "Holli", "HollyLane", "HollywoodBest", "holyforest", "hongyu", "hotlilme74", _
                                    "HowartH", "hres", "HueterdesFeuers", "humster3d", "hylla", "iamkate101", _
                                    "Ian D. Thomas", "IanMPalmer", "IanP", "Ian_C", "IceWolfX", "idler168", _
                                    "IgnisSerpentus", "ilona", "imagica1", "ImagineGrafiX", "Indialasca", "infiniview", _
                                    "Inquisition", "insomniaworks", "Invidia", "ir", "Irish", "IsauraS", _
                                    "islandgirdesigns", "iso2400", "Isyndra", "Iuvenis_Scriptor", "iw43d", "ixdon", _
                                    "Jackie Lewin", "Jacqueline", "jaguarwoman", "jancory", "JaneZek", "JanGiGo", _
                                    "JanneT", "jasmina", "jasonj", "Jayme", "Jaymonjay", "jba", _
                                    "jc", "Jean-Luc_Ajrarn", "jedizebi", "JeffH", "Jen", "Jenai21", _
                                    "jenelson", "jenepooh", "JenniSjoberg", "JenX", "Jepe", "JesterCGI", _
                                    "JFandL", "JHoagland", "jidaho", "jip", "jkd", "jlneveloff", _
                                    "Jochen38", "JOE LE GECKO", "John-Katris", "JohnSurridge", "Jon", "jonathan607", _
                                    "jonbg1", "jtomas", "judee3d", "judith", "juleyanne", "junkbyjen", _
                                    "jvanfleet", "jwiest", "kaciasea", "Kadaj", "kahshe", "kaiZ", _
                                    "kalebdaark", "kaleidica", "kaleya", "Kalypso", "kandeewright", "Kaol", _
                                    "karanta", "karen1573", "karrd", "kassad", "Kassie", "katje", _
                                    "kawecki", "kazzlink", "kebu99", "keihan", "kelc", "ken1171", _
                                    "Kendra", "KenG", "keppel", "kfox", "Khory_D", "Khrys", _
                                    "Kiera", "Kimberly.3D", "kimmarcus", "kirwyn", "KJAM", "klingon", _
                                    "kmatrix", "KnightRanger", "kobamax", "kodesign", "kony", "kore21", _
                                    "kot23", "KRAKERS", "kromekat", "kruse", "krynn", "ktaylor", _
                                    "Kumima", "kurokuma", "kuroyume0161", "kyhighlander59", "KymJ", "kzarah", _
                                    "LadyDoritea", "LadyElf", "LadyJ", "LadyJaiven", "laetia", "Laksmi", _
                                    "Lalita", "Lamdaria", "lastexplorer", "LaurentR", "LaurieA", "LaVonne", _
                                    "LazloHollyfeld", "lembrechtsart", "levius", "lgrant", "lifezy", "lightingarts", _
                                    "Liladieni", "lilflame", "Lillaanya", "LillianaSapphire", "Lilybelles", "linathy", _
                                    "linuxkid76", "liquidanime", "LisaB", "Lisbeth", "Liss0813", "liteluvr", _
                                    "littlefox", "lkiilerich", "lluque", "LMDesign", "lobo75", "LOCK-ON", _
                                    "locust9", "lollypop", "lonerstudio", "LoneWolfPro", "Loopydee1", "Lordfox", _
                                    "LordsWarrior", "lordwulf", "Lory", "LostDragon", "LotusX", "Lovely Lady", _
                                    "LP-AnaSuza", "Lucie", "luciferino", "LuLeLuna", "lululee", "lupadgds", _
                                    "lupus", "lwanmtr", "lygher_xero", "lyma", "Lynne", "lynnJonathan", _
                                    "lyrainbow", "Lyric_", "Lyrra", "L_and_L", "maburkitt", "macelene", _
                                    "macmullin", "MadameL", "maelwenn", "Maeyanie", "Maggee", "Magician", _
                                    "magickmedbh", "Mahna", "Maira", "majesticartist", "Makena", "makot", _
                                    "malia01us", "maniak", "mansoa_98", "mapgraphs", "mapps", "marblecloud", _
                                    "marforno", "Mariamus", "marianne_lacroix", "MarieJinez", "Mariny", "mari_e17", _
                                    "markdc", "MarkyV", "martelo", "martinjbirk", "martinjfrost", "MartinPh", _
                                    "Mask-da", "MaskEdit", "MaskimXul", "matb", "MatCreator", "Mathes_at_work", _
                                    "mattalexander", "matupo", "Maveris", "maxiss", "MayaX", "Mazl", _
                                    "mb4", "MBaker", "MBI3D", "Mechanismo", "Meddlesom", "medevial", _
                                    "megaionstorm", "melamkish", "Melory", "Merizon", "mertext", "messenger", _
                                    "messygurgs", "Mestophales", "Metrini", "MGDesign", "midgit2230", "Midnite_Designer", _
                                    "MikeB51", "MiKo0", "minsk", "Mint", "MirageBay", "Mirandus-Arts", _
                                    "missgrin", "Miss_Digital_World", "MistDragon", "mix_mash", "mizer357", "mlevans", _
                                    "mmogul", "mnagao", "mobius", "Mock", "ModuleOne", "Moebius87", _
                                    "MoeGoofie", "molsmith", "Momcat", "momodot", "Monarch3DDesigns", "montyhack", _
                                    "moochie", "MoonGraphics11", "MoonRose", "Morrighan", "Morris", "motif", _
                                    "motokamishii", "MrGorf", "mrsparky", "msdiva1", "muralist", "muscleman2004", _
                                    "Myske", "Mystic-Nights", "Mystique-", "mytilus", "MyVue", "M_Mistoffelees", _
                                    "n0s4ra2", "Nagus", "Nak Muay", "Nalif", "NaturalMystic3D", "Naunet", _
                                    "Naylin", "Neberkenezer", "neftis", "neilp", "nekoja", "NemesisT", _
                                    "nemirc", "Neomea", "NeraStudios", "nerd", "Nesterenko", "netseawolf", _
                                    "neverwinter", "newhere", "NickyDesigns", "nicu1", "NightCelt", "Nightshift3D", _
                                    "nightsong", "nikhelbig", "nirvy", "nitro115", "noggin", "NomiGraphics", _
                                    "nomuse", "Nouschka-Design", "novelist999", "Nyghtwolf", "nymesis", "OblivionKing", _
                                    "obm890", "OddDitty", "odegami", "offrench", "OKCRandy", "oldskoolPunk", _
                                    "Olimpo", "omega", "Omegachan", "onebaretree", "Oneman", "OOh Betty", _
                                    "OpenMindDesign", "OrcaDesignStudios", "originalkitten", "orion1167", "Ornlu", "osiris9", _
                                    "outoftouch", "OutsideTheBox", "Overlord_Diabolus", "PageOfCups", "Palcelina", "paleman", _
                                    "Pandorian", "PandyGirl", "panko", "Panthalassa", "pappy411", "Papu", _
                                    "pashiel", "PatGoltz", "patslash", "Pauli", "pdblake", "pdm", _
                                    "pdoll", "pdxjims", "pearce", "peemot", "pennykay", "Pen_Is_Envy", _
                                    "Peppi1", "perelredstorm", "PG-Graphics", "ph0enixx", "Phantom", "PhantomSmurf", _
                                    "Pharie82", "PhateGBR", "PhilC", "phoenixwaller", "photoroyalestudio", "photoshopcafe", _
                                    "PickersAngel", "Pinball24", "Piotr", "PixelDust1", "pixelfader", "PixelMagic", _
                                    "pixpax", "pizazz", "pjaj", "Placebo", "Platypus3d", "plazio", _
                                    "plismatm", "plus3d", "Poisen", "Pond969", "Porthos", "Posermatic", _
                                    "Poser_Dreams", "powerage", "prae", "Predatron", "Premier", "Pretty3D", _
                                    "profotograf", "prog", "Propschick", "Prufrock81", "psychohazard", "ptrope", _
                                    "PureEnergy", "pzrite", "qay", "QUADRIGAFX", "Quarker", "QueArres", _
                                    "queequeg", "quim2001", "R4MZ", "Ra Graphics", "raggioverde", "Rainfeather", _
                                    "rainlondon", "RajDArge", "ralaci", "Ralph", "ramhernan", "Ranlinde", _
                                    "Raptura", "ratracer", "ratu", "Ravenhair", "Ravenism", "RavenRaven", _
                                    "Ravnheart", "Ravynsworld", "Rawnrr", "rax", "rchristen", "RCT", _
                                    "RealDeal", "Reallusion", "rebelmommy", "reciecup", "Redhawke", "renapd", _
                                    "Renarts", "resplendentRowan", "ret37", "Rhadeya", "Rhiannon", "ricardo719", _
                                    "Richabri", "Richardphotos", "RIM", "Rio", "rj001", "robert.sharkey", _
                                    "Robotmonster", "rocker333", "rockets", "rodluc2001", "romainperera", "romanceworks", _
                                    "Romantic-3D", "roninthetall", "roogna", "roxcat", "RoxieDee", "royloo", _
                                    "RO_MAN", "rrmmiss", "RubiconDigital", "RubyT", "ruby_dragon", "Rusty21", _
                                    "rwaller", "ryuslilangel", "ryverthorn", "s.37", "sacrako", "sagersweb", _
                                    "sahejaa", "SaintFox", "saiphiel", "saiyan", "SalmonGeek", "SamDillard", _
                                    "SAMS3D", "SamTherapy", "sandraz63", "sandra_bonello", "sarsa", "saschild", _
                                    "SatanicaInc", "ScarlettWoman", "Schlabber", "Schwan", "seang", "secretheart", _
                                    "Sekhmet", "SenshiTaurus", "senyac", "serg", "Serrge", "SGS", _
                                    "shadavar", "shadow06", "ShadowDaleCreations", "shadownet", "Shadow_Fyre", "Shahara", _
                                    "Shariyma", "Sharkx19", "shaybear", "Sheil", "shellyw", "Sherlock", _
                                    "shesa", "ShirleysShowcase", "shogakusha", "sifoto", "SilenceDesigns", "SilencertheVampire", _
                                    "silverblade33", "SilverElf_SE", "SilverHawke", "SilverLynx", "silverspirit", "silverwing3d", _
                                    "SimplySerendipity", "Sinamin", "Sincovich", "SinisterDesigns", "sirjoe", "SirLancelot", _
                                    "si_vincent", "sjallen03", "skinjob3d", "skinmez", "Skipychic", "Skydancer120", _
                                    "SkyeWolf", "skynet88", "Slosh", "SlwMtionDaylite", "smac", "smay", _
                                    "smitthms", "smokebox46and2", "snakebiteS12", "snappertrx", "snoopy1985", "SnowFox102", _
                                    "soccer coach", "solarisonline", "Solidarity", "SolidusSoft", "solitary", "SOman", _
                                    "spamboy", "Spanki", "specs2", "spetsk", "Spike", "Spiritbear", _
                                    "Spiritfoxy", "spothmann", "spratman", "Sprinter", "Stacey_73", "stamate_filip", _
                                    "steerpike", "StefyZZ", "stephaniebt", "Sternenschein", "Steve35", "steveshanks", _
                                    "stoffel", "stolenanjel", "Stone_Camel", "Store Staff", "Stormi", "Stormrage", _
                                    "stormwolf", "Stringy", "Studio11", "StudioTake", "sturkwurk", "SubTigee", _
                                    "suicidegirlz", "sukips", "Surama", "surreality", "svar00g", "Sveva", _
                                    "SWAM", "swfreeman", "Swidhelm", "Syam", "Syltermermaid", "tabala", _
                                    "Talon69", "Talwicca", "tamathy", "Tanaquil", "tastiger", "tatalinn", _
                                    "tball2004", "tclarke2", "Tebok", "Tempus Fugit", "tendom", "teris", _
                                    "Terraga", "Teyon", "TFDesigns", "the hankster", "The-Slinger", "The3dZone", _
                                    "thebert", "TheDaedalus", "thee_immortal_one", "TheMadPainter", "thenodemaster", "ThetaGraphics", _
                                    "thewishmaster", "thip", "ThomasMacCallum", "Thorne", "thunderr", "tialise", _
                                    "TiffT785", "Tiltedhalo", "TIMCORP", "Tina", "TinasDesign", "tinovandeijzen", _
                                    "tivao", "tlg29360", "Tocpe", "tojanetoo", "TolchinEnterprises", "tom3962", _
                                    "tomasball", "TonyBaas", "tonyhag", "too", "ToonBoom_Inc", "Toribev", _
                                    "toshiyo", "Tosun", "ToxicAngel", "trav", "Traveler", "tre329", _
                                    "TrekkieGrrrl", "Triaanna", "tsk", "TT", "Tuesday", "tufif", _
                                    "twodimensions", "TwoSisters", "TygerCub", "type", "Uberskulk", "ulysses30", _
                                    "umblefugly", "uni-code69", "Unicornst", "unitychild", "UOja", "usslopez", _
                                    "Uty-Studio", "VAIRESH", "Val3dArt", "Valea", "Valentin3D", "Valerian70", _
                                    "Vali", "ValkyrieArt", "valkytan", "VanishingPoint", "vbarreto", "VegasLarry", _
                                    "Velen", "venerella", "vexiphne", "victorias", "Victoria_Lee", "VIDandCGI", _
                                    "vielhauer", "vikike176", "vincebagna", "VinnyMac", "Virtual_World", "visio", _
                                    "VisionAiry", "visualgirl", "vok", "Wampyir", "Wappen", "WarmFuzzies", _
                                    "warnimal", "warpcoreproject", "webdancer", "webhexe", "webster2772", "wenke", _
                                    "westonmi", "whammalamma", "whitemagus", "White_Wolf", "whoppersdesign", "WildPepsiChild", _
                                    "William_the_Bloody", "WillNC", "winnston1984", "wishes3d", "Wizardkiss", "WMBJ", _
                                    "wolf359", "WolfeStudios", "Wolfkazzy", "wonderdesign", "woodhurst", "wotdoin", _
                                    "WThomas", "wusamah", "wyrmmaster", "wytchware", "x-siter", "XanderStudios", _
                                    "xaven", "xbook", "Xena", "Xeone", "xil", "xoxroth", _
                                    "Xurge", "xv3d", "xxxander", "y1127j", "yakchat", "Yanelis3D", _
                                    "yangaimin", "yarddog", "yarp", "yatrus", "ynsaen", "yorkshire_pud", _
                                    "Yoro", "youngtrout", "Youniss", "yukonjak", "Yvan", "yve", _
                                    "Zachrael2002", "ZaxysDMI", "Zenman53186", "Zephre", "ZeroEffect", "zew3d", _
                                    "Zhann", "ziggie", "ziggy3d", "zoozee", "zxcvb", "_Al3d_", _
                                    "_ClauDe", "_Fenrissa_", "_samildanach_", "_XXO_", "~DutchAngel~"}

        Dim vdta As New VendorDataTableAdapters.VendorTableAdapter

        Try

            For Each vendor As String In vendors
                Try
                    vdta.Insert(vendor)
                Catch ex As OleDbException
                    If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                        Throw
                    End If
                End Try
            Next

            UpgradeLog.WriteEntry("AddRenderosityVendors Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("AddRenderosityVendors failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddRenderosityVendors failed: " & ex.Message)
            Throw
        Finally

        End Try

    End Sub

    Private Shared Sub AddPoserProsVendors()

        Dim vendors As String() = {".yvonne.", "12rounds", "3-D Arena", "3dCritter", "3Don", "4blueyes", _
                                    "7SeAs", "aaa3d", "Aaronheart", "AbaloneLLC", "Abraham", "Accidental Alchemy", _
                                    "AdamWright", "Aerozon", "Agatha", "AGentleMuse", "Aioria", "akahastur", _
                                    "Al3d", "alainarose", "Alatariel", "AllenArt", "almdesign", "amlaborde", _
                                    "Anain", "Angela3D", "AngelMichael", "Angelmoon", "angielyn", "anitapsp", _
                                    "Anniebel", "anny", "Antje", "anykl", "Aphoennix", "AprilYSH", _
                                    "Araara", "Arasii", "Ardiva", "Aremis", "aren", "Ariel", _
                                    "Arien", "Arki", "Artemis_Sun", "ArtGrafx", "artroland", "AS3Design", _
                                    "Ascended Spirit", "AtlantiStyle", "Atze0571", "Aurora_in_a_bag", "A_", "bazze", _
                                    "beatle_trekkie", "Bice", "BigKat70_", "billy-home", "binarybodies", "biomekk", _
                                    "bknoh", "black*widdow", "blankpixel", "Blazerwiccan", "blecch", "blondie9999", _
                                    "BlueBeard", "bluemoon3dart", "bluevenus", "Bobbie25", "Borus", "boundless", _
                                    "bovistock", "BrianR", "BrokenWings", "bryden", "butterfly_fish", "c567591", _
                                    "Calypso", "camelia", "CandeeKis", "CANTROS", "Capsces", "carlos-teran", _
                                    "Carmen0307", "Carole", "CarolineG", "Cascarda", "Catherine_Todd", "cbt", _
                                    "ccmt", "Chaotic Sanity", "chasmata", "chevybabe25", "chriscox", "ChromeTiger", _
                                    "Chromewerks", "Cimerone", "Cin-", "Clarissa", "Claywoman", "Cool-Graphic", _
                                    "corearts", "Corinne", "cowham", "cplymill", "Creative Renders", "CrimsonRose", _
                                    "crystalwizard", "cwshorty", "Cyllan", "Cyncro007", "Cyphre", "c_stone_bush", _
                                    "D.W. Mitchell", "dabas", "Daio", "dalinise", "Damsel", "DanaanD", _
                                    "dangerkitty", "Danie", "DanielleSylvie", "DarkAngel68", "dawnsthemes", "Deadly_Whisper", _
                                    "decon", "Dedman", "DeeDee", "Deimos", "Derawyn", "Desideria", _
                                    "designfera", "designthedream", "dex", "dfsmetsfan", "Diane", "dido6", _
                                    "Digiport", "Dimension 3D", "DiNeerG", "dmblnd", "Dodger", "dodixy", _
                                    "dolfijntjes", "Dolly", "dorkati", "Dorthe", "doublebite", "dpanzee", _
                                    "dragonchild75", "dragonlady", "dreampaint", "DreamWarrior", "DTigerWoman", "Dutch Angel", _
                                    "dwilmes", "Ecstasy", "edain", "eirian", "electranaut", "ElectricAardvark", _
                                    "elizabyte", "EllPro", "En!y", "Enigma3D", "Eowyn", "Esterix", _
                                    "Evilinnocence", "ExprssnImg", "ExtremeThemes", "FaerieGuild", "FairyRealm", "FantastArt", _
                                    "Fatale", "Faveral", "Fazeon", "Fire Angel", "Fisty", "fmorgan", _
                                    "folkvangar", "fracturedmoon", "frances", "FrozenAngel", "Gareee", "gecco", _
                                    "GilaMonster", "Gilded Lily", "gildedgecko", "gillb", "Giving Chest", "Glimmer", _
                                    "glozwurld", "GoblinWorks", "goldtassel", "Gorodin", "GothKurlz", "gr8g8s", _
                                    "graphixdezine", "Gregorius", "Greybro", "grfkdsgn", "grimjerk", "grnbriar", _
                                    "Guarie", "gypsyangell", "hahtor", "hannah", "Hawke", "Helen", _
                                    "HH_Drache", "him666sweetheart", "hipchick", "Hisminky", "hitman47", "Hogwarden", _
                                    "HollywoodBest", "HueterdesFeuers", "iamkate", "IceWolf", "idler168", "imagica", _
                                    "incognito11967", "insomniaworks", "Invidia", "InvisibleSun", "IsauraS", "ixdon", _
                                    "Jaguarwoman", "Jamesadactyle", "JDexter", "Jen", "Jenai21", "jessyca", _
                                    "JGreenlees", "Jim Burton", "jip", "judee3d", "K-Team", "kaleya", _
                                    "kandacewright", "karanta", "Kassia", "katcrouch", "kathymoon", "katstuff", _
                                    "kawecki", "kazzlink", "keihan", "Kendra", "kennect", "Kfox", _
                                    "Khrys", "Kirby", "Kit", "Kumima", "kurokuma", "lairemjd", _
                                    "Laksmi", "Lalita", "Larry Wolf", "lastexplorer", "LaurieA", "lazboy", _
                                    "LDs3Ds", "Lesthat", "levius", "libernull", "life3d", "lifezy", _
                                    "lilflame", "Lisbeth", "Liss0813", "LitlTunie", "lluque", "lobo75", _
                                    "Locke21", "Loopydee", "Lordfox", "Lucie", "Luciferino", "luckyred", _
                                    "lululee", "lupus", "Lwanmtr", "lyma", "lyRainbow", "Lyric", _
                                    "Lyrra", "m0rriganshad0w", "mabfairyqueen", "macelene", "mada", "Maelwenn", _
                                    "MAKENA", "Malefic", "mansoa_98", "mapgraphs", "marblecloud", "marforno", _
                                    "Marianne", "marilacroix", "mariny", "Marttelo", "MaskimXul", "MatCreator", _
                                    "maxiss", "Mea", "Meddlesom", "megaionstorm", "megan33", "Melory", _
                                    "Merizon", "messenger", "Mestophales", "MidnightStorm03", "Mikenron", "Mint", _
                                    "Mirandus-Arts", "mmogul", "Moebius", "mommastacie", "Monarch 3D Designs", "moonfire", _
                                    "Morghana", "Morris", "motif", "mrsparky", "muralists", "Muscleman", _
                                    "MyDiva", "MysticalWarrior", "MysticBlueRaven", "Mystique-", "mytilus", "Nae", _
                                    "Neo10", "Neomea", "Nerd", "Netherworks", "nfredman", "nicu1", _
                                    "Ninja", "nirvy", "NorbertG", "Nouschka-Design", "Nyghtwolf", "OddDitty", _
                                    "OKCRandy", "OrcaDesignStudios", "originalkitten", "outoftouch", "ozbrat", "Page_Of_Cups", _
                                    "paigeloveslarry", "Pandy Girl", "panko", "pannca", "PaulaK", "pbnj", _
                                    "pdm", "pdxjims", "Pendarian", "Peti", "ph0enixx", "PickersAngel", _
                                    "Pika", "pixpax", "Pizazz", "Placebo", "Pooka", "posermommy", _
                                    "PoserPros Original", "posfan", "prbaker", "Predatron", "prog", "pspmouse1", _
                                    "psychohazard", "Ptrope", "Purr3D", "qay", "Rabite_X", "Ravenhair", _
                                    "Ravnheart", "Ravyn", "Rawnrr", "rax", "RealitysPoison", "redspark", _
                                    "renapd", "resplendentRowan", "rgl76it", "Rhadeya", "Rhiannon", "Rhonnie", _
                                    "richabri", "RNKarenER", "robartz", "rockets", "rodluc2001", "Romantic 3D", _
                                    "Ronstuff", "Rosetta", "Rowens", "RoxieDee", "royloo", "rwaller", _
                                    "ryuslilangel", "ryverthorn", "Saffireeyes", "sahejaa", "SamTherapy", "santiago", _
                                    "saphphx", "sarfrench", "Schlabber", "seammer", "Sean Martin", "secretheart", _
                                    "serpentis", "ShadowDaleCreations", "Sheil", "shellyw", "Shesa", "Shpman58", _
                                    "Silencer", "SilverElf", "Silverleif Studios", "Silverlie", "Simon3d", "SimplySerendipity", _
                                    "sinamin", "sinsister", "Skipychic", "SkyeWolf", "skynet88", "SnowFox102", _
                                    "solitary", "Sorceress77", "spamboy", "Spanki", "Speed77", "spicebunny", _
                                    "spideyk21", "spinneyhead", "Spiritfoxy", "spiritual", "staigerman", "starlight64", _
                                    "stephaniebt", "Stephen S", "Sternenschein", "Sternentraum", "stoffel", "stonemason", _
                                    "Stormi", "Studio11", "sturkwurk", "sukips", "Surama", "Susa", _
                                    "suziea", "SWAM", "Swantje", "SyaPed", "Syltermermaid", "Tallameia", _
                                    "Talon69", "Taria", "teris", "TesseractSpace", "TexasGal", "the3dwizard", _
                                    "the3dzone", "thebert", "theImmortal", "thip", "Tigee", "tigerboyjayce", _
                                    "tlc01", "tonyhag", "torinouta", "Tosun", "tove", "ToxicAngel", _
                                    "trekkiegrrrl", "TrishM", "Troy Halliday", "tsk", "TSW", "Tuckerwilly Designs", _
                                    "Tuesday", "twilightdesign", "tyger_purr", "tynana", "Unicornst", "Upir", _
                                    "VAIRESH", "Valandar", "Valea", "valkytan", "Vampir3Princess", "venux", _
                                    "VictoriasStyle", "VisionAiry", "visualgirl", "webster2772", "westonmi", "whatie", _
                                    "whiskeysierra", "whopper", "wildaboutbirds", "wishes3d", "Wizardtim", "WMBJ1963", _
                                    "wotdoin", "Wylder", "wytchware", "xaven", "Xena", "xixao", _
                                    "Xurge", "xxxander", "y1127j", "Yassia", "Yuna", "Yve", _
                                    "zachrael"}

        Dim vdta As New VendorDataTableAdapters.VendorTableAdapter

        Try

            For Each vendor As String In vendors
                Try
                    vdta.Insert(vendor)
                Catch ex As OleDbException
                    If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                        Throw
                    End If
                End Try
            Next

            UpgradeLog.WriteEntry("AddPoserProsVendors Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("AddPoserProsVendors failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddPoserProsVendors failed: " & ex.Message)
            Throw
        Finally

        End Try

    End Sub


    Private Shared Sub AddRuntimeDNAVendors()

        Dim vendors As String() = {}

        Dim vdta As New VendorDataTableAdapters.VendorTableAdapter

        Try

            For Each vendor As String In vendors
                Try
                    vdta.Insert(vendor)
                Catch ex As OleDbException
                    If ex.ErrorCode <> ExpectedPrimaryKeyViolationErrorCode Then
                        Throw
                    End If
                End Try
            Next

            UpgradeLog.WriteEntry("AddRuntimeDNAVendors Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("AddRuntimeDNAVendors failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("AddRuntimeDNAVendors failed: " & ex.Message)
            Throw
        Finally

        End Try

    End Sub


#End Region

    Private Shared Sub UpdateVersion()

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = String.Format(UpdateVersionSQL, CurrentVersion)
            comm.Connection = conn

            comm.ExecuteNonQuery()

            UpgradeLog.WriteEntry("UpdateVersion Succeeded.")

        Catch ex As OleDbException
            UpgradeLog.WriteEntry("UpdateVersion failed: " & ex.Message)
            Throw
        Catch ex As Exception
            UpgradeLog.WriteEntry("UpdateVersion failed: " & ex.Message)
            Throw
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Sub

    Private Shared Function GetVersion() As Single

        Dim conn As New OleDbConnection

        Try

            conn.ConnectionString = My.Settings.PoserFilesConnectionString
            conn.Open()

            Dim comm As New OleDbCommand
            comm.CommandType = CommandType.Text
            comm.CommandText = VersionSQL
            comm.Connection = conn

            Dim version As Single = CType(comm.ExecuteScalar, Single)

            Return version

        Catch ex As Exception
            Return DefaultVersion
        Finally
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End Try

    End Function

    Public Shared Function Upgrade() As Boolean

        Dim success As Boolean = False

        Try
            Dim version As Single = GetVersion()
            If version <> CurrentVersion Then

                UpgradeLog.OpenLog()

                If version = DefaultVersion Then
                    CreateSettingsTable()
                End If

                'version 1.1 upgrades
                AddCommentsColumn()
                AddDSOnlyColumn()
                CreateInstalledRuntimesTable()
                AddMinPoserVersionColumn()

                'version 1.2 upgrades
                AddInstalledColumn()
                AddLocalImageColumn()
                AddImageNameColumn()
                AddConnectionStatusColumn()
                CreateFiguresTable()
                CreateFileForFigureTable()

                'version 1.3 upgrades
                AddNewFigures()
                CreateRequiredProductTable()
                CreateProductTypeTable()
                CreateFileProductTypeTable()
                AddRequirementsColumn()

                'version 1.4 Upgrades
                AddNewFigures2()
                AddPricePaidColumn()
                AddFileSizeColumn()
                AddDateOfDownloadColumn()
                CreateFileImageTable()
                CreateFileArtistTable()
                AddFileFigureConstraint()
                AddOrderNumberColumn()
                AddImportedIdColumn()
                AddImportedFromColumn()

                'version 1.5 Upgrades
                AddFileArtistConstraint()
                AddFileImportedIndex()

                'version 1.6 Upgrades
                AddNewProviders()
                AddUserAddedColumn()
                AddReadMeColumn()
                CreateLicenseTable()
                AddLicenseColumn()

                'version 1.7 Upgrades
                AlterLicenseColumn()
                AddLicenseIndex()
                AddFileArtistArtistIndex()

                'version 1.8 Upgrades
                AddVendorIndex()

                'version 1.11 Upgrades
                AddActualLocationColumn()
                AddNewFigures3()
                CreateVendorTable()
                AddRenderosityVendors()
                AddPoserProsVendors()
                'AddRuntimeDNAVendors()

                'version 2.0 upgrades
                If Not ProjectTrackingUpgrader.CreateProjectTables Then
                    Throw New Exception
                End If

                UpdateVersion()

            End If

            success = True

        Catch ex As Exception
            success = False
        Finally
            UpgradeLog.CloseLog()
        End Try

        Return success

    End Function

    Public Shared Function NewVersionAvailable() As Boolean

        Try

            Dim versionDom As New XmlDocument
            versionDom.Load(My.Settings.FileUrl & VersionFileName)
            Dim latestVersion As Single = CType(versionDom.DocumentElement.InnerText, Single)
            Return latestVersion > CurrentVersion

        Catch ex As Exception
            Throw New VersionException(VersionErrorMessage)
        End Try

    End Function

End Class
